var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var Schema = mongoose.Schema;

var PostSchema = new Schema({
  // 地区
  area:  {type: String},
  // 标题
  title: {type: String},
  // 内容
  body: {type: String},
  // photo
  photo: [Schema.Types.Mixed],
  // 联系人
  contact_name: {type: String},
  // 联系电话
  contact_phone: {type: Number},
  // 引用分类表
  category: {type: Schema.Types.ObjectId, ref:'Category'},
  // 文章类型
  category_slug: {type: String, required: true},
  // 作者ID
  authorId: {type: String},
  // 引用用户表
  author: {type: Schema.Types.ObjectId, ref: 'User'},
  // 文章赞数量
  meta: [Schema.Types.Mixed],
  // 文章浏览量
  skim_num: {type: Number, default: 0},
  // 文章评论
  comments: [Schema.Types.Mixed],
  // 是否置顶
  top: {type: Boolean, default: false},
  // 置顶时间
  topTime:  {type: Date},
  // 是否加精
  elite: {type: Boolean, default: false},
  // 文章创建时间
  created_at: {type: Date, default: Date.now}
});

// 生成Model
module.exports = mongoose.model('Post', PostSchema);
